#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

int main(int argc,char *argv[])
{
    //子进程
    if (fork()  == 0)
    {
        printf("加载新程序之前的代码\n");;

        //加载新程序，并传递参数3
        execl("/bin/ls","/bin/ls","-l","-h",NULL);

        printf("子进程为加载成功");
    }
    else        //父进程
    {
        //等待子进程的退出
        int status;
        int ret = waitpid(-1,&status,0);
        if (ret > 0)
        {
            if (WIFEXITED(status))
            {
                printf("[%d]:子进程[%d]的退出值是:%d\n",getpid(),ret,WEXITSTATUS(status));
            }
            else
            {
                printf("暂无僵尸子进程\n");
            }            
        }
        
    }
}